#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include "hthread.hpp"
#include "simd_thl.h"

__mpe__ int main(int argc, char **argv){
  hthread_init();
  double *tmp = new double[10000];
  for (int i = 0; i < 10000; i ++){
    tmp[i] = i;
  }
  double sum = 0;
  hparallel([=, &sum]() __cpe__ mutable{
    double lsum = 0;
    for (int i : hparallel_iterate<16>(0, 10000, hlinear_in(tmp))){
      lsum += tmp[i];
    }

    lsum = hreduce(lsum, std::plus<double>{});
    if (_MYID == 0){
      sum = lsum;
    }
  });
  printf("%f\n", sum);
  return 0;
}
